<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Head_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();
		$data=array();

	} 	
		
	public function create_user_type($insert)
	{
		$this->db->insert('user_type',$insert);
	}
	
	public function create_department($insert)
	{
		$this->db->insert('department',$insert);
	}
	
	public function add_group($name,$parent,$additional_data){
		
		$data = array(
			    'name'   => $name,
				'parent'   => $parent
		 );
		// print_r($data);exit;
		$this->db->insert('acc_group',$data);
			
	}
		
	public function get_group(){
	$q = $this->db->get('acc_group');
		if($q->num_rows() > 0) {
			foreach (($q->result()) as $row) {
				$data[] = $row;
			}
				
			return $data;
		}
		
	}
	

	public function get_headList(){
		//echo "i am here";exit;
		$this->db->select('head.*,acc_group.name as group_name');
		$this->db->from('head');
	//	$this->db->where('head.group ='.$id);
		$this->db->join('acc_group','head.group=acc_group.id');
		return $query = $this->db->get();

	
	
	
		//$query = $this->db->get('head');
	//return $query;

		
		
		} 

public function get_head($id){
	$query = $this->db->get_where('head', array('id' => $id));
	return $query;

	}

public function insert($name, $group, $additional_data){
		
		$data = array(
			    'name'   => $name,
				'group'   => $group
		 );
	
		$this->db->insert('head',$data);
	}

/*public function get_groups(){
	$this->db->select('acc_group.*,projects.name');
		$this->db->from('tasks');
		$this->db->where('tasks.id ='.$id);
		$this->db->join('projects','tasks.project_id=projects.id');
		return $this->db->get()->row_array();
		$query = $this->db->get('acc_group');
	return $query;
}
*/
public function edit_head($id){
		$query = $this->db->get_where('head', array('id' => $id));
		return $query;
	}

public function update($edit_id, $data){
		$this->db->update('head',$data,array('id'=>$edit_id));
	}

public function delete($id){
		$this->db->delete('head',array('id'=>$id));		
	}


public function getHeadByID($id){
		$query = $this->db->get_where('head', array('id' => $id));
		return $query->row_array();
	
	}


public function check_head($name,$group){
		$query = $this->db->get_where('head', array('name' => $name,'group' => $group));
		$n=$query->num_rows();
		if($n >0){
			
			return 1;
			}else{
			return 0;
				}
	
	}


}
